package com.shrct.businessprocess.purchase.impl;

import com.shrct.businessprocess.purchase.RCBudgetContract;
import com.shrct.businessprocess.purchase.RCProductDeliver;
import com.shrct.businessprocess.purchase.RCProductDeliverItem;
import com.shrct.businessprocess.purchase.impl.RCBudgetContractImpl;
import com.shrct.businessprocess.purchase.impl.RCProductDeliverItemImpl;
import com.shrct.businessprocess.purchase.proxy.RCProductDeliverProxy;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("RCPRODUCTDELIVER_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rcproductdeliver")
public class RCProductDeliverImpl extends BaseModelObject implements RCProductDeliver {
  public RCProductDeliverImpl() {
    super();
  }
  
  public RCProductDeliverImpl(final RCBudgetContract contract) {
    super();
    this.contract = contract;
  }
  
  private Date date;
  
  public Date getDate() {
    return this.date;
  }
  
  public RCProductDeliver setDate(final Date date) {
    this.date = date;
    return this;			
    
  }
  
  private String comment;
  
  public String getComment() {
    return this.comment;
  }
  
  public RCProductDeliver setComment(final String comment) {
    this.comment = comment;
    return this;			
    
  }
  
  private String location;
  
  public String getLocation() {
    return this.location;
  }
  
  public RCProductDeliver setLocation(final String location) {
    this.location = location;
    return this;			
    
  }
  
  private String branch;
  
  public String getBranch() {
    return this.branch;
  }
  
  public RCProductDeliver setBranch(final String branch) {
    this.branch = branch;
    return this;			
    
  }
  
  @JoinColumn(name = "contract_id")
  @ManyToOne(targetEntity = RCBudgetContractImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCBudgetContract contract;
  
  public RCBudgetContract getContract() {
    return this.contract;
  }
  
  public RCProductDeliver setContract(final RCBudgetContract contract) {
    this.contract = contract;
    return this;			
    
  }
  
  @OneToMany(targetEntity = RCProductDeliverItemImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy = "deliver")
  private Collection<RCProductDeliverItem> items = new java.util.ArrayList<com.shrct.businessprocess.purchase.RCProductDeliverItem>();;
  
  public Collection<RCProductDeliverItem> getItems() {
    return this.items;
  }
  
  public RCProductDeliver removeAllItems() {
    for(RCProductDeliverItem obj : this.items){
    	getObjectFactory().delete(obj);
    }
    this.items.clear();
    return this;	
    
  }
  
  public RCProductDeliver removeFromItems(final RCProductDeliverItem rCProductDeliverItem) {
    this.items.remove(rCProductDeliverItem);
    getObjectFactory().delete(rCProductDeliverItem);
    return this;
    
  }
  
  public void cancelDeliver(final RCProductDeliverItem item) {
    item.cancelDeliver();
    this.removeFromItems(item);
  }
  
  public static RCProductDeliver create(final RCBudgetContract contract, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.purchase.RCProductDeliver rCProductDeliver = new com.shrct.businessprocess.purchase.impl.RCProductDeliverImpl(
    	contract
    );
    objectFactory.create(rCProductDeliver);
    return rCProductDeliver;			
    
  }
  
  public static RCProductDeliver createRCProductDeliverImpl(final RCBudgetContract contract, final IObjectFactory objectFactory, final Procedure1<RCProductDeliver> init) {
    com.shrct.businessprocess.purchase.RCProductDeliver rCProductDeliver = new com.shrct.businessprocess.purchase.impl.RCProductDeliverImpl(
    	contract
    );
    objectFactory.create(rCProductDeliver);
    init.apply(rCProductDeliver);
    
    return rCProductDeliver;			
    
  }
  
  public RCProductDeliverProxy toProxy() {
    com.shrct.businessprocess.purchase.proxy.RCProductDeliverProxy proxy = new com.shrct.businessprocess.purchase.proxy.RCProductDeliverProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
